var formProce="5", //表单当前所处流程
    formState="0", //表单状态 
    userJob="4";   //角色

$(function(){

    $('.ym-date').val(moment().format("YYYY-MM"));
    $('.ym-date').datetimepicker({
        language:  'zh-CN',
        format: 'yyyy-mm',
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 3,
        minView:3,
    });
    $('.ymdhm-date').val(moment().format("YYYY-MM-DD HH:mm"));
    $('.ymdhm-date').datetimepicker({
        language:  'zh-CN',
        format: 'yyyy-mm-dd hh:ii',
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        minView:0,
    });

	//弹窗显示
    $(document).on("click",".et-review-btn",function(){
    	$("[formTo='et_review']").show();
        showTicketForm(formProce, formState, userJob);
    })
    .on("click",".et-process-btn",function(){
    	$("[formTo='et_process']").show();
    })

    //两票显示切换
    $(document).on("click",".btnto-work",function(){
    	$(".stop-tickets").slideUp(function(){
    		$(".work-tickets").slideDown();
            $(".stop-tickets-btns").hide();
            $(".work-tickets-btns").show();
    	});
    })
    .on("click",".btnto-stop",function(){
    	$(".work-tickets").slideUp(function(){
    		$(".stop-tickets").slideDown();
            $(".work-tickets-btns").hide();
            $(".stop-tickets-btns").show();
    	});
    })


})

//根据当前两票所处步骤、两票状态、登录角色进行表单的展示
function showTicketForm(formProce, formState, userJob){
    for (var i = 0; i < 5; i++) {
        checkProceShow(formProce, formState, userJob,i);
    }
    if (formProce=="5") {
        $(".stop-tickets-btns .btnto-work").show();
    }

}

//检测每一栏信息是以哪种形式展示
function checkProceShow(formProce, formState, userJob, proce){

    //proce搭配job  表示当前步骤能做操作的职位
    var job = "0";
    if (proce == "0") {
        roleRow = "zhiban";
        job = "0";
    }
    else if(proce == "1") {
        roleRow = "yunxing";
        job = "1";
    }
    else if(proce == "2") {
        roleRow = "bumen";
        job = "2";
    }
    else if(proce == "3") {
        roleRow = "diaodu";
        job = "3";
    }
    else if(proce == "4") {
        roleRow = "lingdao";
        job = "4";
    }
    var roleP = $('[doRole="'+roleRow+'"] p'),
        roleInput = $('[doRole="'+roleRow+'"] .result-input'),
        roleTime = $('[doRole="'+roleRow+'"] .result-time');
    if (formProce == proce) {
        if (formState == "0") {
            if (userJob == job) {
                roleInput.show();
            }
        } 
        else{
            roleTime.show();
        }
    }
    else if(formProce > proce){
        roleP.text();
        roleTime.show();
    }

}